// 生成相应格式的日期方法 可选添加时间
export let addDate = function (curDate, i = 0) {
  var initalTime = new Date(
    new Date(curDate).getTime() + i * 24 * 60 * 60 * 1000
  )
  var year = initalTime.getFullYear()
  var month = `0${initalTime.getMonth() + 1}`.slice(-2)
  var date = `0${initalTime.getDate()}`.slice(-2)
  return `${year}-${month}-${date}`
}

// 获取日期1-日期2中每天。
export let getDayGroup = (start, end) => {
  let oneDayTime = 24 * 60 * 60 * 1000
  let num = (end.getTime() - start.getTime())/oneDayTime
  let arr = []
  if (num > 1) {
    // num === 0 === 1  > 1
    let time = start.getTime()
    while(num > 1) {
      time = time + oneDayTime
      arr.push(addDate(time))
      num--
    }
    arr = [addDate(start), ...arr, addDate(end)]
  } else if (num === 1) {
    arr = [addDate(start), addDate(end)]
  } else {
    arr[0] = addDate(end)
  }
  return arr
}